/*
 * @Author: hemingyu39 hemingyu39@163.com
 * @Date: 2024-12-31 08:35:09
 * @LastEditors: hemingyu39 hemingyu39@163.com
 * @LastEditTime: 2025-01-17 14:00:49
 * @FilePath: \Smart_Lock\main\Inf\Inf_BDR6120.c
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
#include "Inf_BDR6120.h"
#define BDR_A_PIN 4
#define BDR_B_PIN 5
#define BDR_A_H gpio_set_level(BDR_A_PIN, 1)
#define BDR_A_L gpio_set_level(BDR_A_PIN, 0)
#define BDR_B_H gpio_set_level(BDR_B_PIN, 1)
#define BDR_B_L gpio_set_level(BDR_B_PIN, 0)


void Inf_BDR6120_Init(void)
{

    gpio_config_t config;
    config.mode = GPIO_MODE_OUTPUT;
    config.pin_bit_mask = (1 << BDR_A_PIN) | (1 << BDR_B_PIN);
    config.intr_type = GPIO_INTR_DISABLE;
    config.pull_down_en = GPIO_PULLDOWN_DISABLE;
    config.pull_up_en = GPIO_PULLUP_DISABLE;

    gpio_config(&config);

    BDR_A_L;
    BDR_B_L;
}

void Inf_BDR6120_Ready(void)
{
    BDR_A_L;
    BDR_B_L;
}

void Inf_BDR6120_Forward(void)
{
    BDR_A_H;
    BDR_B_L;
}

void Inf_BDR6120_Backward(void)
{
    BDR_A_L;
    BDR_B_H;
}

void Inf_BDR6120_Brake(void)
{
    BDR_A_H;
    BDR_B_H;
}

void Inf_BDR6120_OpenLock(void)
{
    // 正传1秒 反转1秒 待命
    Inf_BDR6120_Forward();
    vTaskDelay(1000 / portTICK_PERIOD_MS);
    Inf_BDR6120_Backward();
    vTaskDelay(1000 / portTICK_PERIOD_MS);
    Inf_BDR6120_Ready();
}

void Inf_BDR6120_CloseLock(void)
{
    // 正传1秒 反转1秒 刹车
    Inf_BDR6120_Backward();
    vTaskDelay(1000 / portTICK_PERIOD_MS);
    Inf_BDR6120_Forward();
    vTaskDelay(1000 / portTICK_PERIOD_MS);
    Inf_BDR6120_Brake();
}

